/**
 * 获取请求参数

 * @param {Object} str
 */
export function queryStringToObject(str) {
    if (str.indexOf('?') > -1) {
        str = str.substring(str.indexOf('?') + 1)
    }
    const data = {}
    const strArr = str.split('&')
    for (let i = 0; i < strArr.length; i++) {
        const paramArr = strArr[i].split('=')
        data[paramArr[0]] = paramArr[1] || null
    }

    return data
}
/**
 * 是否IOS环境
 */
export function isIos() {
    const u = navigator.userAgent;
    // var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
    return !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
}
/**
 * 跳转eleApp

 * @param {Object} url
 */
export function toElmApp(url) {
    // 必须要 encodeURIComponent 两次饿了么的页面才能正常接收
    const encodeUrl = encodeURIComponent(encodeURIComponent(url));
    window.location.href = 'https://links.ele.me/stage/alsc-growth-download.html?fastmode=1&url=eleme%3A%2F%2Fweb%3Fo2i_code%3Dundefined%26action%3Dali.open.nav%26module%3Dh5%26packageName%3Dme.ele%26bc_fl_src%3Dundefined-0%26fastmode%3D1%26url%3D' +
        encodeUrl +
        '%2526_ltracker_share_schema%253Dapp_outside_poster%26navType%3D0&restoreId=1621851&imei=undefined$oaid=undefined$idfa=undefined&uid=undefined';
}
/**
 * 执行拷贝
 * @param {Object} text
 */
export function exec(text) {
    $('#copy-btn').attr('data-clipboard-text', text)
}